<?php
namespace app\app\controller;

use think\Controller;
use think\Request;
class Mine extends Controller {
    private $baseinfo;
    private $product;
    private $message;
    
    public function _initialize() {
        $this->baseinfo = new Baseinfo();
        $this->product  = new Product();
        $this->message  = new Message();
    }

    /*
     * app--我的--信息获取
     * 1.获取基本信息，头像、店名
     * @return 
     */
    public function index() {
        if(request()->isPost()) {
            $data = input('post.');
            $username = $data['post_username'];
            // 基本信息
            $ret = $this->baseinfo->index($username);
            return json_encode($ret, 320);
        }
    }
    
    /*
     * app--我的--密码安全
     * 重置密码
     * @return 
     */
    public function newPassword() {
        if(request()->isPost()) {
            $data           = input('post.');
            $username       = $data['post_username'];
            $pwd            = $data["pwd"];
            $password       = $data['password'];
            $postConfirmPwd = $data['postconfirmpwd'];
            $ret = $this->baseinfo->newPassword($username, $pwd, $password, $postConfirmPwd);
            return json_encode($ret, 320);
        }
    }
    
    /*
     * app--我的--个人信息
     * 修改商户名称
     * @return 
     */
    public function newBisName() {
        if(request()->isPost()) {
            $data     = input('post.');
            $username = $data['post_username'];
            $bisname  = $data['bis_name'];
            $ret = $this->baseinfo->newBisName($username, $bisname);
            return json_encode($ret, 320);
        }
    }
    
    /*
     * app--我的--更新头像
     * 
     * @return 
     */
    public function avatar(Request $request) {
        $file = $request->file('file');
        $username = $_POST['username'];    // 设置保存图片路径的用户
        $ret = $this->baseinfo->newAvatar($file, $username);
        return json_encode($ret, 320);
    }
}